export type Callback<K,V> = (key:K,value:V)=>void;
export class Dectionary<K,V>{
    private keys:K[] =[];
    private vals:V[] =[];
    // private _size:number =0;
    // map:[[]]
    get size(){
        return this.keys.length
    }
    set(key:K,val:V){
        const index= this.keys.indexOf(key);
        if(index <0){
            this.keys.push(key)
            this.vals.push(val)
        }else{
            this.vals[index] = val 
        }
        console.log(this.vals)
        console.log(this.keys)
    }
    // 遍历
    
    forEach(callback:Callback<K,V>){
      
       this.keys.forEach((key,index)=>{
        const value= this.vals[index];
        callback(key,value)
       })
    };
    has(key:K){
        return this.keys.includes(key)
    }
    delete(key:K){
        const index = this.keys.indexOf(key);
        if(index < 0){
            return ;
        }
        if(index >=0){
            this.keys.splice(index,1)
            this.vals.splice(index,1)
        }
    }
    

}